package com.msb.controller;

import com.msb.pojo.User;
import com.msb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.List;

/**
 * @Auther: daot
 * @Date: 2021/5/15 - 05 - 15 - 14:39
 * @Description: com.msb.controller
 * @version: 1.0
 */
@Controller
@RequestMapping()
public class UserController {
    @Autowired
    private UserService userService;
   @RequestMapping("/toLogin")
   public String toLogin(){
       return "login";
   }
    @RequestMapping("/LoginSuccess")
    public String LoginSuccess(String uname, String password, Model model){
            //查询用户是否存在
            User user = userService.queryByName (uname,password);
            if(null != user){
                System.out.println (user);
                return "success";
            }else{
                //返回登录页面
                model.addAttribute ("data","该用户不存在");
                return "login";
            }
    }
    //注册界面
    @RequestMapping("/register")
    public String register(){
       return "register";
    }
    @RequestMapping("/RegisterSuccess")
    public String RegisterSuccess(Model model,User user){
       //将数据加入数据库中
        int add = userService.add (user);
        System.out.println ("数据加入成功");
        model.addAttribute ("data","注册成功，请登录");
        return "login";
    }

}
